package api

import (
	"api-gateway/basic/inits"
	user "api-gateway/basic/user_proto"
	"api-gateway/handler/request"
	"api-gateway/handler/response"
	"github.com/gin-gonic/gin"
)

// UserCheckIn
// @Summary      签到
// @Description  签到
// @Tags         用户模块
// @Accept       json
// @Produce      json
// @Param        user  body      request.CheckIn  true  "用户参数"
// @Success      200  {object}  response.Response
// @Failure      400   {object}  response.Response
// @Security TokenAuth
// @Router       /points/CheckIn [post]
func UserCheckIn(c *gin.Context) {
	userId := c.GetUint("userId")
	var req request.CheckIn
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, 400, "参数错误", err.Error())
		return
	}
	checkin, err := inits.UserClient.CheckIn(c, &user.CheckInReq{
		UserId: int64(userId),
	})
	if err != nil {
		response.Error(c, 400, "签到失败", err.Error())
		return
	}
	response.Success(c, "签到成功", checkin)
}

// GetCheckInList
// @Summary      获取签到列表
// @Description  获取签到列表
// @Tags         用户模块
// @Accept       json
// @Produce      json
// @Param        user  query      request.GetCheckInList  true  "用户参数"
// @Success      200  {object}  response.Response
// @Failure      400   {object}  response.Response
// @Security TokenAuth
// @Router       /points/GetCheckInList [get]
func GetCheckInList(c *gin.Context) {
	userId := c.GetUint("userId")
	var req request.GetCheckInList
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, 400, "参数错误", err.Error())
		return
	}
	list, err := inits.UserClient.GetCheckInList(c, &user.GetCheckInListReq{
		UserId: int64(userId),
		Year:   int32(req.Year),
		Month:  int32(req.Month),
	})
	if err != nil {
		response.Error(c, 400, "获取签到列表失败", err.Error())
		return
	}
	response.Success(c, "获取签到列表成功", list)
}

// MakeUpCheckIn
// @Summary      获取积分
// @Description  获取积分
// @Tags         用户模块
// @Accept       json
// @Produce      json
// @Param        user  body      request.MakeUpCheckIn  true  "用户参数"
// @Success      200  {object}  response.Response
// @Failure      400   {object}  response.Response
// @Security TokenAuth
// @Router       /points/MakeUpCheckIn [post]
func MakeUpCheckIn(c *gin.Context) {
	userId := c.GetUint("userId")
	var req request.MakeUpCheckIn
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, 400, "参数错误", err.Error())
		return
	}
	makeUp, err := inits.UserClient.MakeUpCheckIn(c, &user.MakeUpCheckInReq{
		UserId: int64(userId),
		Date:   req.Date,
	})
	if err != nil {
		response.Error(c, 400, "补签失败", err.Error())
	}
	response.Success(c, "补签成功", makeUp)
}

// GetCheckInInfo
// @Summary      获取签到信息
// @Description  获取签到信息
// @Tags         用户模块
// @Accept       json
// @Produce      json
// @Param        user  query      request.GetCheckInInfo  true  "用户参数"
// @Success      200  {object}  response.Response
// @Failure      400   {object}  response.Response
// @Security TokenAuth
// @Router       /points/GetCheckInInfo [get]
func GetCheckInInfo(c *gin.Context) {
	userId := c.GetUint("userId")
	var req request.GetCheckInInfo
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, 400, "参数错误", err.Error())
		return
	}
	info, err := inits.UserClient.GetCheckInInfo(c, &user.GetCheckInInfoReq{
		UserId: int64(userId),
	})
	if err != nil {
		response.Error(c, 400, "获取签到信息失败", err.Error())
		return
	}
	response.Success(c, "获取签到信息成功", info)
}
